﻿
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>新增生产计划</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <script src="~/js/layui/layui.js"></script>
    <link href="~/js/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
        <li class="layui-nav-item" style="float:left;">
            <button id="btn-update" type="button" name="btn_update" onclick="saveData()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1005;</i>保存数据
            </button>
        </li>
        <li class="layui-nav-item" style="float:left;padding-left:20px">
            <button id="btn-sync" type="button" onclick="closeWin()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1007;</i>关闭页面
            </button>
        </li>
    </ul>
    <div class="layui-card" style="margin-top:10px">
        <div class="layui-card-body" style="padding-top:4%">
            <form  class="layui-form layui-col-space5" id="mForm" style="margin-left:2%">

                <div class="layui-form-item">
                    <div class="layui-input-group" style="float:left;">
                        <div class="layui-input-inline">
                            <input type="text" name="gxInfo" placeholder="关联工序" class="layui-input" id="gxInfo" style="width:150%">
                            
                        </div>
                    </div>
                    <div class="layui-input-group" style="float:left;margin-left:14%">
                        <div class="layui-input-inline">
                            <select id="relationType" name="relationType">
                                <option value="">数据类型</option>
                            </select>
                        </div>
                    </div>
                   

               
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-group" style="float:left;">
                        <input type="text" id="relationName" name="relationName" placeholder="关联存货信息" class="layui-input" style="width:420%">
                        <div class="layui-input-suffix" style="cursor: pointer;padding-left:267%" onclick="SelectProduct()">
                            <i class="layui-icon layui-icon-more-vertical"></i>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group" style="float:left;">
          
                        <input type="text" id="fieldCode" name="fieldCode" placeholder="字段编码" class="layui-input" >
                        
                    </div>
                    <div class="layui-input-group" style="float:left;margin-left:7%">
                        <input type="text" name="fieldName" placeholder="字段名称" id="fieldCode"  class="layui-input" style="width:150%">
                    </div>
                    <div class="layui-input-group" style="float:left;margin-left:15%">
                        <input type="text" name="fieldOrder" placeholder="字段序号" class="layui-input" id="fileldOrder">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group" style="float:left;">
                      <select id="fieldType" name="fieldType" autocomplete="off">
                            <option value="">字段类型</option>
                        </select>
                    </div>
                    <div class="layui-input-group" style="float:left;margin-left:5.5%">
                        <input type="text" name="groupCode" placeholder="分组编码" class="layui-input" id="groupCode">
                    </div>
                    <div class="layui-input-group" style="float:left;margin-left:8%">
                        <select id="singleRow" name="singleRow">
                            <option value="">是否单行</option>
                            <option value="0" selected>否</option>
                            <option value="1">是</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <textarea placeholder="数据源内容" id="dSoure" name="dSoure" class="layui-textarea"></textarea>
                </div>
                <input type="hidden" name="relationCode" id="relationCode">
                <input type="hidden" name="gxCode" id="gxCode">
                <input type="hidden" name="id" id="id">
            </form>
        </div>
    </div>
    <div class="layui-card" style="margin-top:6px">
        <div class="layui-card-body ">
            <div class="layui-card-body" id="layui-table-main">
                <table class="layui-hide" id="list" lay-filter="list"></table>
            </div>
        </div>
    </div>
    <form id="qForm">
        <input type="hidden" id="s-gxCode" name="s-gxCode" />
        <input type="hidden" id="s-proCode" name="s-proCode" />
    </form>
</body>
</html>
<script src="~/js/sysweb/gystandard.js"></script>
<script type="text/html" id="barDemo">
    <a title="编辑" href="javascript:;" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
    <a title="删除" href="javascript:;" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>
<script>
    var gxCode = "";
    $(function () {
        gxCode = getUrlVariable("gxCode");
        var gxName = getUrlVariable("gxName");
        $("input[ name='gxInfo']").val(gxName + "(" + gxCode + ")");
        $("#gxInfo").attr("readonly", "readonly");
        $("input[ name='gxCode']").val(gxCode);
        $("input[ name='s-gxCode']").val(gxCode);
        DictionaryDropDown("fdType", "fieldType", "Y");
        DictionaryDropDown("pqt", "relationType", "");
        loadData();
    })
    /**
    数据保存
    **/
    function saveData() {
        $.ajax({
            url: "../ProductSet/UpdateGxForm",
            data: { datas: JSON.stringify(FormToJson("mForm")) },
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                    layer.msg("保存成功");
                    loadData();
                } else {
                    layer.msg(rsl.message);
                }
            }
        });
    }
    function SelectProduct() {
        let url = "../Basic/SelectInventory?isSingle=0";
        var t = $("#relationType").val();
        if (t == "") {

        } else {
            if (t == "PType") {
                url = "../Basic/SelectProductType?isSingle=0";
            } else if (t == "PType") {
                url = "../Basic/SelectProductType?isSingle=0";
            }
            InfoOpenPage(url, "存货选择", "95%", "90%");
        }

    }

    function getChildPar(cData) {
        var cNames = "", cCode = "";
        for (var i = 0; i < cData.length; i++) {
            cCode += cData[i].proCode + ",";
            cNames += cData[i].proName + ",";
        }
        $("input[ name='relationCode']").val(cCode.slice(0, -1));
        $("input[ name='relationName']").val(cNames.slice(0, -1));
        $("input[ name='s-proCode']").val(cCode.slice(0, -1));
        loadData();
    }
    /**
     工序表单设置
      **/
    function loadData() {
        layui.use('table', function () {
            var table = layui.table;
            var condition = JSON.stringify(FormToJson("qForm"));
            var dUrl = '../ProductSet/getDataList?dataType=gxf&condition=' + condition;

            //给table赋值
            table.render({
                elem: '#list'
                , url: dUrl //数据接口
                , title: '数据列表'
                , page: true //开启分页
                , even: true
                , id: "tData"
                , limits: [20, 50, 100]
                , limit: 20 //每页默认显示的数量
                , cols: [[
                    { field: 'fieldCode', title: '字段编码', width: 120 }
                    , { field: 'fieldName', title: '字段名称', width: 130 }
                    , { field: 'fieldType', title: '字段类型', width: 100 }
                    , { field: 'fieldOrder', title: '字段序号', width: 90 }
                    , { field: 'groupCode', title: '分组编码', width: 90 }
                    , { field: 'dSoure', title: '数据源', width: 140 }
                    , { field: 'relationName', title: '关联存货', width: 130 }
                    , { field: 'right', title: '操作', width: 100, align: 'center', toolbar: '#barDemo' }
                ]], done: function (res, curr, count) {

                    currPage = curr;
                    //TablePowerHide();
                }
            });

            //监听行工具事件
            table.on('tool(list)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent == 'edit') {
                    $.each(data, function (name, value) {
                        if (name == "singleRow" || name == "fieldType" || name == "relationType") {
                            $("#" + name + " option[value='" + value + "'] ").attr("selected", true);
                        } else if (name == "dSoure") {
                            $("#dSoure").html(value);
                        } else {
                            $("input[ name='" + name + "']").val(value);
                        }
                    });
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    })


                } else if (layEvent == 'del') {
                    if (data.hasChild == "1") {
                        layer.msg("此大类已配置子工序，请先删除子工序。");
                    }
                    else {
                        layer.confirm('确认要删除该数据？', function (index) {
                            $.ajax({
                                //url: "../Basis/DelCommonData",
                                url: "../ProductSet/DelFGXData",
                                type: "post",
                                data: { dataId: data.id },
                                success: function (data) {
                                    if (data.Result) {
                                        layer.msg("删除成功");
                                        obj.del();
                                    } else {
                                        layer.msg(data.Message);
                                    }
                                    loadData();
                                }
                            });
                            layer.close(index);
                        });
                    }
                }
            });


        });
    }
</script>

